package cn.itmantzy.org.controller;

import cn.itmantzy.basic.exception.BusinessException;
import cn.itmantzy.basic.util.AjaxResult;
import cn.itmantzy.org.domain.Shop;
import cn.itmantzy.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private IShopService shopService;

    @PostMapping("/settlement")
    public AjaxResult register(@RequestBody Shop shop){
        try {
            shopService.settlement(shop);
            return AjaxResult.getAjaxResult();
        } catch (BusinessException e) {
            e.printStackTrace();
            // 当进行注册时，数据库中含有该用户信息，抛出异常告知用户，该用户已存在，直接登录即可
            return AjaxResult.getAjaxResult().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.getAjaxResult()
                    .setSuccess(false)
                    .setMessage("保存失败，请稍后再试！！！");
        }
    }

}
